package ch.sfug.anim.tween.property {
	import flash.display.DisplayObject;
	
	import ch.sfug.anim.tween.CompositeTween;		

	/**
	 * @author loop
	 */
	public class Resizer extends CompositeTween {

		public function Resizer( d:DisplayObject, dur:uint ) {
			tween = new PropertyTween( d, dur );
		}
		
		public function resizeTo( width:Number, height:Number, easeWidthBoth:Function = null, easeHeight:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(width) ) 	obj[ "width" ]  = { to: width, easing:easeWidthBoth };
			if( !isNaN(height) ) 	obj[ "height" ] = { to: height, easing:( easeHeight == null ) ? easeWidthBoth : easeHeight };
			PropertyTween( tween ).tween(obj);
		}

		public function resizeToWidth( width:Number, ease:Function = null ):void {
			var obj:Object = new Object();
			obj[ "width" ] = { to: width, easing: ease };
			PropertyTween( tween ).tween(obj);
		}

		public function resizeToHeight( height:Number, ease:Function = null ):void {
			var obj:Object 	= new Object();
			obj[ "height" ] = { to: height, easing: ease };
			PropertyTween( tween ).tween(obj);
		}

		public function resizeFromTo( widthfrom:Number, widthto:Number, heightfrom:Number, heightto:Number, easeWidthBoth:Function = null, easeHeight:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(widthfrom) && !isNaN(widthto) ) obj[ "width" ] 	 = { from: widthfrom, to: widthto, easing:easeWidthBoth };
			if( !isNaN(heightfrom) && !isNaN(heightto) ) obj[ "height" ] = { from: heightfrom, to: heightto, easing:( easeHeight == null ) ? easeWidthBoth : easeHeight };
			PropertyTween( tween ).tween(obj);
		}

		public function resizeBy( widthamount:Number, heightamount:Number, easeWidthBoth:Function = null, easeHeight:Function = null ):void {
			var obj:Object = new Object();
			if( !isNaN(widthamount) && widthamount != 0 ) 	obj[ "width" ] = { by: widthamount, easing:easeWidthBoth };
			if( !isNaN(heightamount) && heightamount != 0 ) obj[ "height" ] = { by: heightamount, easing:( easeHeight == null ) ? easeWidthBoth : easeHeight };
			PropertyTween( tween ).tween(obj);
		}
				/**
		 * sets the target the fade
		 */
		public function set target( d:DisplayObject ):void {
			tween.target = d;
		}
				/**
		 * returns the display object that fades
		 */
		public function get target(  ):DisplayObject {
			return DisplayObject(tween.target);
		}
				/**
		 * sets the duration of the Resizer
		 */
		public function set duration( n:Number ):void {
			tween.duration = n;
		}
				/**
		 * returns the duration of the Resizer
		 */
		public function get duration( ):Number {
			return tween.duration;
		}
				/**
		 * applies new x/y position
		 */
		public function apply( new_width:Number = NaN, new_height:Number = NaN ):void {
			var obj:Object = new Object();
			if( !isNaN(new_width) )  obj["width"] 	= new_width;
			if( !isNaN(new_height) ) obj["height"] 	= new_height;
			PropertyTween( tween ).apply(obj);
		}
	}
}
